import { HTTP } from '../../../utils/http.js'
import api from '../../../utils/api.js'
import { config } from '../../../utils/config'
import utils from "../../../utils/util" 

let http = new HTTP()
var app = getApp();
let timer;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl: config.imgUrl,
    payBtn : true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let order_no = options.order;
    let paymeth = options.paymeth;
    // let order_no = 'IM20200722722007534924412901';
    this.setData({
      order_no,
      pay_method : paymeth
    })
    
  

    // if(prevPage.indexOf('myAllOrderList') ){

    // }
    // this.getOrderDetail();
    
    
  },

  // 获取订单详情
  getOrderDetail(){
    let that = this;
    wx.showLoading({title: '加载中'})
    let order_no = this.data.order_no;
    http.request({
      url: api.integralOrderDetails,
      method: 'GET',
      data: {
          order_no : order_no
      },
      success: (res) => { 
        wx.hideLoading();
        let result = res.data
        if(res.code == 200){
          that.setData(result)

          if(result.status == 1){
            timer = setInterval (function () {
              that.showtime()
            }, 1000); 
          }
         

        }
          
      },
      fail: (res) => {

      }
  })
  },
  
  // 电话
  service(e){
    let phone = e.currentTarget.dataset.phone;
    console.log(phone);
    wx.makePhoneCall({
      phoneNumber : phone.toString()
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  goAddComment(){
    app.globalData.comproduct = {
      product_id : this.data.orderproduct.product_id,
      order_no : this.data.order_no,
      pay_method : this.data.pay_method,
      orderproduct : this.data.orderproduct.product_info.productInfo
    }
    wx.navigateTo({
      url: '/pages/pointsMall/postComments/postComments'
    })
  },
  CommentList(e){
    let id = this.data.orderproduct.product_id
    wx.navigateTo({
      url : '/pages/pointsMall/comments/comments?id='+id
    })
  },
  onReady: function () {
    
  },
  applyRefund(){
    let order = this.data.order_no;
    utils.getInfo(api.inteIsCanafter, "GET", {order_no : order},false).then(res => {
        wx.navigateTo({
          url: `/pages/refund/pomAdd/pomAdd?order=${order}`,
        })
    })         
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getOrderDetail();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})